{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d46c43b6",
   "metadata": {},
   "source": [
    "----\n",
    "* 2023-10-11\n",
    "* 课程：python\n",
    "* week04(上课周)\n",
    "----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3f51244f",
   "metadata": {},
   "source": [
    "# 1.本周内容\n",
    "\n",
    "## 1.数值\n",
    "\n",
    "## 2.字符串\n",
    "\n",
    "## 3.range ()函数\n",
    "\n",
    "## 4.for循环"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "26e01e3c",
   "metadata": {},
   "source": [
    "# 2.数值\n",
    "\n",
    "> 1. [数值的概念--Python的教程](https://docs.python.org/zh-cn/3/tutorial/introduction.html#numbers)\n",
    "> 2. [数值的总结--Python的参考](https://docs.python.org/3/library/stdtypes.html)\n",
    "> 3. 数值的分类（type）\n",
    ">> 1. int\n",
    ">> 2. float\n",
    ">> 3. complex"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "71ebe4a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2+2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "13a0c29e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "50 - 5*6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "dba8e452",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.6"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "8/5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "eccee718",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17 // 3  # 取整"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d3a23ff1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "17 % 3  # 取余"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "4dde1490",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5 ** 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "aaa415c4",
   "metadata": {},
   "outputs": [],
   "source": [
    "width = 25\n",
    "height = 50"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "aa72d4ca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1250"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "width * height"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "572b76f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数值的方法\n",
    "abs(-8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "3459eabb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数值类型\n",
    "\n",
    "a = 2023"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "bc003e82",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "8ff0d0bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "PI = 3.1415926"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "efec3154",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "float"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(PI)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "8377f4cd",
   "metadata": {},
   "outputs": [],
   "source": [
    "b = 3 + 2j"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "82a91548",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "complex"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(b)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4ee886ac",
   "metadata": {},
   "source": [
    "# 3. 字符串\n",
    "\n",
    "> 1. 字符串的概念与形态\n",
    "> 2. 字符串的一般方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "67334e73",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'spam eggs'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'spam eggs'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "069dd8de",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Paris rabbit got your back :)! Yay!'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Paris rabbit got your back :)! Yay!\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0dc2c52b",
   "metadata": {},
   "source": [
    "* 笔记：如果里面是数值，其结果仍为字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "7d12ed27",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1975'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'1975'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "bbc8a11d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type('1975')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "5393ef4e",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "unterminated string literal (detected at line 1) (3578565646.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Cell \u001b[1;32mIn[25], line 1\u001b[1;36m\u001b[0m\n\u001b[1;33m    'doesn't'\u001b[0m\n\u001b[1;37m            ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unterminated string literal (detected at line 1)\n"
     ]
    }
   ],
   "source": [
    "'doesn't'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "a66a9e4e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "78ce3134",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串的重要特征：序列\n",
    "\n",
    "地址 = \"广州市从化区温泉大道882号广州南方学院\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "110127ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州市从化区温泉大道882号广州南方学院'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7ef3f486",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 序列实践\n",
    "# 序列：自然数顺序从左到右依次排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "830c9cf0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址 [0]  # 取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "17a67389",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'从化'"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[3:5]  # 切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "c62a70dd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "abb35212",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'学院'"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 请用负数取出来“学院”\n",
    "地址[-2: ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "88235d48",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址.count(\"广州\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12e31c03",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 通过上面的方法尝试输出“温泉大道”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "9672ad15",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'温泉大道'"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[6:10]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a443c3f",
   "metadata": {},
   "source": [
    "## 4.for循环和range()方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "cb5211c7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广,\n",
      "州,\n",
      "市,\n",
      "从,\n",
      "化,\n",
      "区,\n",
      "温,\n",
      "泉,\n",
      "大,\n",
      "道,\n",
      "8,\n",
      "8,\n",
      "2,\n",
      "号,\n",
      "广,\n",
      "州,\n",
      "南,\n",
      "方,\n",
      "学,\n",
      "院,\n"
     ]
    }
   ],
   "source": [
    "# 把如下的操作称为：循环遍历\n",
    "for item in 地址:\n",
    "    print(item + \",\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "248fd9d5",
   "metadata": {},
   "source": [
    "* 笔记：range()可以确定范围，并且决定for循环的次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "394a05c2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "15\n",
      "16\n",
      "17\n",
      "18\n",
      "19\n"
     ]
    }
   ],
   "source": [
    "for i in range(20):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "34993544",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "15\n",
      "16\n",
      "17\n",
      "18\n",
      "19\n"
     ]
    }
   ],
   "source": [
    "for i in range(10,20):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "a95b779e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello~\n",
      "hello~\n",
      "hello~\n",
      "hello~\n",
      "hello~\n",
      "hello~\n",
      "hello~\n",
      "hello~\n",
      "hello~\n",
      "hello~\n",
      "hello~\n",
      "hello~\n",
      "hello~\n",
      "hello~\n",
      "hello~\n",
      "hello~\n",
      "hello~\n",
      "hello~\n",
      "hello~\n",
      "hello~\n"
     ]
    }
   ],
   "source": [
    "for i in range(20):\n",
    "    print(\"hello~\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0589aa1d",
   "metadata": {},
   "source": [
    "## for循环实践"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1866e108",
   "metadata": {},
   "source": [
    "### 实践一：创建学号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "2dab17ce",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "202301030101\n",
      "202301030102\n",
      "202301030103\n",
      "202301030104\n",
      "202301030105\n",
      "202301030106\n",
      "202301030107\n",
      "202301030108\n",
      "202301030109\n",
      "202301030110\n",
      "202301030111\n",
      "202301030112\n",
      "202301030113\n",
      "202301030114\n",
      "202301030115\n",
      "202301030116\n",
      "202301030117\n",
      "202301030118\n",
      "202301030119\n",
      "202301030120\n",
      "202301030121\n",
      "202301030122\n",
      "202301030123\n",
      "202301030124\n",
      "202301030125\n",
      "202301030126\n",
      "202301030127\n",
      "202301030128\n",
      "202301030129\n",
      "202301030130\n",
      "202301030131\n",
      "202301030132\n",
      "202301030133\n",
      "202301030134\n",
      "202301030135\n",
      "202301030136\n",
      "202301030137\n",
      "202301030138\n",
      "202301030139\n",
      "202301030140\n",
      "202301030141\n",
      "202301030142\n",
      "202301030143\n",
      "202301030144\n",
      "202301030145\n",
      "202301030146\n",
      "202301030147\n",
      "202301030148\n",
      "202301030149\n",
      "202301030150\n",
      "202301030151\n",
      "202301030152\n",
      "202301030153\n",
      "202301030154\n",
      "202301030155\n",
      "202301030156\n",
      "202301030157\n",
      "202301030158\n",
      "202301030159\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,60):\n",
    "#    print(i)\n",
    "    if i > 9:\n",
    "        print(\"2023010301\" + str(i))\n",
    "    else:\n",
    "         print(\"20230103010\" + str(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "301c8841",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
